package controller;

import java.io.File;
import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import pojo.Item;
import service.ItemService;

@Controller
// @RequestMapping("item")
public class ItemController {

	@Autowired
	private ItemService itemService;

	@RequestMapping(value = { "itemList", "itemList2" })
	public ModelAndView itemList() {
		ModelAndView mav = new ModelAndView();

		List<Item> itemList = itemService.getItemList();

		mav.addObject("itemList", itemList);
		// mav.setViewName("/WEB-INF/jsp/itemList.jsp");
		mav.setViewName("itemList");
		System.out.println("ItemController.itemList.....");
		return mav;
	}

	/*
	跳转到修改商品页面
	处理器默认支持的传递参数有
	model 返回数据模型
	request 处理请求
	reponse 用于响应
	 */
	@RequestMapping("itemEdit")
	public String itemEdit(Model model, @RequestParam(value = "id", required = true, defaultValue = "1") Integer ids) {
		// 查询商品信息
		Item item = itemService.getItemById(ids);
		// model返回数据模型
		model.addAttribute("item", item);
		// mav.addObject("item", item);
		//返回string，直接是返回对应的视图名字的jsp
		return "itemEdit";
	}




}
